import promiseMiddleware from 'redux-promise';
import thunkMiddleware from 'redux-thunk';
import {createLogger} from 'redux-logger';

const loggerMiddleware = createLogger({
  collapsed: false,

  // only log in development mode
  // eslint-disable-next-line no-undef
  predicate: () => __DEV__,

  stateTransformer: state => state,

  // transform immutable action payloads to plain objects
  // eslint-disable-next-line no-confusing-arrow
  actionTransformer: action =>
    action && action.payload && action.payload
      ? {...action, payload: action.payload}
      : action
});

// define store middlewares as an array
export default [
  promiseMiddleware,
  thunkMiddleware,
  loggerMiddleware
];
